package com.hy.study;

import com.hy.study.conditional.TestAspect;
import com.hy.study.conditional.TestConditional;
import com.hy.study.conditional.TestLog;
import com.hy.study.dto.Car;
import com.hy.study.dto.Person;
import com.hy.study.dto.User;
import com.hy.study.listener.TestApplicationListener;
import org.springframework.context.annotation.*;

/**
 * @author huyong
 * @date 2024 年 01 月 02 日 18:04: 27
 */
@Configuration
@PropertySource(ignoreResourceNotFound = true,value = {"classpath:person.properties"},encoding = "UTF-8")
@ComponentScan(basePackages = {"com.hy.study"},includeFilters = {@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE,value = User.class)},useDefaultFilters = false)
@Import(value = {Car.class,TestBeanPostProcessor.class,TestComponent.class,JdbcConfig.class, TestApplicationListener.class})//使用import 引入第三方组件的类
public class MainConfig {

    @Bean
    public Person person(){
        return new Person();
    }


    @Bean(initMethod = "init",destroyMethod = "destory")
    public TestAspect testAspect(){
        return new TestAspect();
    }

    @Bean
    //@Lazy //懒加载 只有在使用的时候才会加载该bean
    @Conditional(value = {TestConditional.class}) //这里表示当容器中 testAspect 组件初始化完毕之后才会初始化 testLog 组件
    public TestLog testLog(){
        return new TestLog();
    }
}
